package it.sd.utility;


public class URLUtility {
	
    public static URLBean getUrlBean(String url) throws Exception {
	
    	URLBean bean = new URLBean();
    	
    	int i = url.indexOf("//");
    	if (i>0) {
    		bean.setProtocol(url.substring(0, i-1));
    		url = url.substring(i+2);
    	}
    	
    	i = url.indexOf("/");
    	if (i>0) {
    		bean.setHost(url.substring(0, i));
    		url = url.substring(i+1);
    	} else {
    		bean.setHost(url);
    		url = "";
    	}
    	
    	
    	i = url.indexOf("?");
    	if (i>0) {
    		bean.setAction(url.substring(0, i));
    		url = url.substring(i+1);
    	} else {
    		bean.setAction(url);
    		url = "";
    	}
    	
    	while (url.length()>0) {
    		i = url.indexOf("&");
    		String p;
    		if (i>-1) {
    			p = url.substring(0, i);
    			url = url.substring(i+1);
    		} else {
    			p = url;
    			p = "";
    		}
    		
    		i = p.indexOf("=");
    		if (i>-1) {
    			bean.addParam(p.substring(0, i), (p.substring(i+1)));
    		}
    		
    	}

    	return bean;
    }
    
}
